define([], function() {
	return{
		title:['<a href="user.html">个人中心</a>', "商城管理", "订单管理"],
		init:function(content){
			let form = content.children("form");
			let table = content.children("table");
			let search = [];
			let shopOrderItemState = content.find("select[name='shopOrderItemState']");
			let productTemplate = content.find("._productTemplate");
			let tableInit = function() {
				let actionEvent = {
					"change .shopOrderItemState": function(e, value, row) {
						e.target.disabled = true;
						$.post(
							"shop/order-fh.do", {
								"shopOrderItemId": row.shopOrderItemId,
								"shopOrderItemState": e.target.value
							},
							function(data) {
								e.target.disabled = false;
								if(data.ok) {
									toastr.success("修改订单状态成功");
								} else {
									toastr.error("修改订单状态失败：" + data.message);
								}
							}, "json"
						);
					},
					"click .temp1": function(e, value, row) {
						$("#shopOrderItemAddress").val(row.shopOrderItemAddress);
						$("#modal").modal('show');
						
						$(".btnxgs").on("click", function() {
							var shopOrderItemAddressx = $("#shopOrderItemAddress").val();
							$.post(
								"shop/order-xg.do",
								{"shopOrderItemId" : row.shopOrderItemId,
								"shopOrderItemAddress" : shopOrderItemAddressx},
								function(data){
									if(data.ok) {
										//$(".modal").modal('hide');
										$("#modal").modal('hide');
										toastr.success("修改成功");
										table.bootstrapTable('refresh');
										//$("#ordermain").trigger("reset");
									} else {
										toastr.error("修改是失败：" + data.message);
									}
								},"json"
							); 
						});
						
					}
				}
				table.bootstrapTable({
					url:'shop/order-page-ajax.s', // 表格数据来源
					method:"get",
					sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
					pageNumber: 1, //初始化加载第一页，默认第一页
					pageSize: 10, //每页的记录行数（*）
					pageList: [5, 10, 15, 20, 30, 50], //可供选择的每页的行数（*）
					pagination: true, //是否显示分页（*）
					dataField: "list",
					toolbar: form,
					queryParamsType: "",
					queryParams: function(p) {
						let ps = [].concat(search);
						ps.push({
							"name": "current",
							"value": p.pageNumber
						});
						ps.push({
							"name": "rowMax",
							"value": p.pageSize
						});
						ps.push({
							"name": "sortName",
							"value": p.sortName
						});
						ps.push({
							"name": "sortOrder",
							"value": p.sortOrder
						});
						return ps;
					},
					columns:[{
						field: 'shopOrderItemId',
						title: '订单项编号',
						align: "center",
						sortable: true,
						sortName: "PRODUCT_ID",
						width: 30
					},{
						field: 'shopOrderItemUserName',
						title: '用户名',
						align: "center",
						sortable: true,
						sortName: "PRODUCT_ID",
						width: 50
					},{
						field: 'shopOrderItemProductName',
						title: '产品名称',
						align: "center",
						sortable: true,
						sortName: "PRODUCT_ID",
						width: 150
					},{
						field: 'shopOrderItemProductPrice',
						title: '商品单价',
						align: "center",
						sortable: true,
						sortName: "PRODUCT_ID",
						width: 60
					},{
						field: 'shopOrderItemAddress',
						title: '地址 ',
						align: "center",
						sortable: true,
						sortName: "PRODUCT_ID",
						width: 200
					},{
						field: 'shopOrderItemRemarks',
						title: '备注',
						align: "center",
						sortable: true,
						sortName: "PRODUCT_ID",
						width: 100
					},{
						field: 'shopOrderItemState',
						align: "center",
						title: '订单状态',
						width: 100,
						events: actionEvent,
						formatter: function(value, row, index, field) {
							let s = productTemplate.children("select");
							s.children().removeAttr("selected").filter("[value='" + value + "']").attr("selected", "selected");
							return productTemplate.html();
						}
					}, {
						field: 'temp1',
						align: "center",
						title: '修改地址',
						width: 60,
						events: actionEvent,
						formatter: function(value, row, index, field) {
							return '<a class="temp1" href="javascript:void(0);">修改地址</a>';
						}
					}]
				});
			};
			
			form.on("submit",function(){
				/*alert(form.serializeArray());
				console.info(form.serializeArray());*/
				search = form.serializeArray();
				table.bootstrapTable('refresh');
				return false;
			});
			
			tableInit();
			
			
		}
	}
});	